<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>打印作物信息</title>
</head>
<link rel="stylesheet" type="text/css" href="../css/dataTables.bootstrap.css" />
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css"/>
<link href="../css/style.css" rel="stylesheet" type="text/css" />

<body onload="initDataTable()">
<!--位置div-->
<!--DataTable-->
    <div style="width: 70%">
        <div style="margin:10px;padding-right:0">
            <table class="table table-striped table-bordered table-hover datatable" id="record_list">
                <thead>
                <tr>
                    <th class="table-checkbox"><input type="checkbox" class="group-checkable" data-set="#record_list .checkboxes" /></th>
                    <th>作物ID</th>
                    <th>作物名称</th>
                    <th>作物数量(kg)</th>
                    <th>作物状态</th>
                    <th>作物备注</th>
                    <th>作物栽培周期</th>
                    <th>修改/删除</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
    <!--datatable数据显示-------------------------------------------------------------------------------------------->
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../js/jquery.uniform.min.js"></script>
<script type="text/javascript" src="../js/jquery.dataTables.min.js"></script>

<script>

    function getParent_id(){
        var result;
        var url=decodeURI(window.location.search); //获取url中"?"符后的字串
        if(url.indexOf("?") != -1) {
            result = url.substr(url.indexOf("=")+1);
        }
        return result;
    }
    let Child_id=getParent_id();

    // 保存当前的dataTable信息
    let type=this.location.search;
    let data=type.split("sort=");
    let sort=data[1];
    // 获取上页传入的信息
    sort=decodeURI(sort);

    function initDataTable(){
        // 全局设置监听
        $(".sure").click(function (){
            $(".tip").fadeOut(100);
        });
        // 2.弹窗的取消
        $(".cancel").click(function (){
            $(".tip").fadeOut(100);
        });
        $(".tiptop a").click(function (){
            $(".tip").fadeOut(100);
        });
        // 初始化DataTable！
        init();
    }

    var resultList=[];
    //获取作物信息-------------------------------------------------------------------------------------------------------
    function init(){
        $('.datatable').dataTable({
            "paging": true,
            "searching": true,
            "retrieve":true,
            // "destroy":true,
            "oLanguage": {
                "aria": {
                    "sortAscending": ": activate to sort column ascending",
                    "sortDescending": ": activate to sort column descending"
                },
                "sProcessing": "处理中...",
                "sLengthMenu": "_MENU_ 记录/页",
                "sZeroRecords": "没有匹配的记录",
                "sInfo": "显示第 _START_ 至 _END_ 项记录，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项记录，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项记录过滤)",
                "sInfoPostFix": "",
                "sSearch": "查询:",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                }
            },
            "aoColumns": [{
                "mRender": function (data, type, full) {
                    sReturn = '<input type="checkbox" class="checkboxes" value="' + data + '"/>';
                    return sReturn;
                }, "orderable": false
            }, {
                "mRender": function (data, type, full) {
                    sReturn = "<div>"+full.crop_id+"</div>";
                    return sReturn;
                }, "orderable": true
            }, {
                "mRender": function (data, type, full) {
                    sReturn = "<div>"+full.crop_name+"</div>";
                    return sReturn;
                }, "orderable": true
            },  {
                "mRender": function (data, type, full) {
                    sReturn ="<div>"+full.crop_number+"</div>";
                    return sReturn;
                }, "orderable": true
            },{
                "mRender": function (data, type, full) {
                    sReturn = "<div>"+full.crop_status+"</div>";
                    return sReturn;
                }, "orderable": true
            },{
                "mRender": function (data, type, full) {
                    sReturn = "<div>"+full.crop_remark+"</div>";
                    return sReturn;
                }, "orderable": true
            }, {
                "mRender": function (data, type, full) {
                    sReturn = "<div>"+full.crop_datetime+"</div>";
                    return sReturn;
                }, "orderable": true
            },{
                "mRender": function (data, type, full) {
                    resultList.push(full);
                    sReturn = "<a href=\"javascript:ModifyCropShow("+full.crop_id+")\">【修改记录】</a><a href=\"javascript:DeleteCropRecord(" + full.crop_id + ")\">【删除记录】</a>";
                    return sReturn;
                }, "orderable": true
            }
            ],
            "aLengthMenu": [[5, 10, 15, 20, 25, 40, 50, -1], [5, 10, 15, 20, 25, 40, 50, "所有记录"]],
            "fnDrawCallback": function () {
                $(".checkboxes").uniform();
                $(".group-checkable").uniform();
            },
            "sAjaxSource": "../cropModule_file_servlet_action?Action=getcropRecordList&value="+Child_id

        });
        $('.datatable').find('.group-checkable').change(function () {
            var set = jQuery(this).attr("data-set");
            var checked = jQuery(this).is(":checked");
            jQuery(set).each(function () {
                if (checked) {
                    $(this).attr("checked", true);
                    $(this).parents('tr').addClass("active");
                } else {
                    $(this).attr("checked", false);
                    $(this).parents('tr').removeClass("active");
                }
            });
            jQuery.uniform.update(set);
        });
        $('.datatable').on('change', 'tbody tr .checkboxes', function () {
            $(this).parents('tr').toggleClass("active");
        });
    }
</script>
</html>
